Repository navigation
fix(preview): reload fetches images edited on disk again - #1067
Merged
Merged
Conversation
Reload re-read the document but kept every image: a block whose markup did not change is not re-inserted, and an unchanged URL is served from the webview's decoded copy. Each explicit reload now stamps a generation onto <img>, so only the blocks holding an image are replaced, and their local URLs carry it as a query the asset protocol ignores.
Raw HTML can hold the text <img inside an attribute value. A quoted stamp closed that attribute early; an unquoted one cannot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1066. RoyiAvital regenerated the images a document embeds, clicked Reload, and the preview kept the old pictures.
Reload re-reads the document, not its images. The preview only re-inserts blocks whose rendered markup changed, so an image block whose Markdown is the same is left in place. A re-inserted
<img>would not help either: its asset URL is unchanged, and the webview reuses the image it already decoded for that URL. This predates the incremental preview: the earlier{@html}article also skipped an identical string.Each explicit reload (Reload from disk, and Reload on the external-change bar) now bumps an image generation. The preview stamps it onto every
<img>in the renderer's markup, which changes exactly the blocks that hold an image, andprocessBlockMarkupturns it into?v=Non local asset URLs. The asset protocol reads only the URL path, and export, copy and "Save image as" parse the path too, so the query reaches nothing but the cache. Remote images keep the URL their author wrote.Left alone: refreshing when an image changes on disk without a reload. That needs a watcher per image, as VS Code's preview has; MarkText and Obsidian also only refresh on request. The generation is shared by all tabs, so after a reload another tab's image blocks are re-inserted once, the next time that tab renders. The stamp is a text replace, so
<imgwritten inside raw HTML's attribute values or comments gets it too; it is unquoted, so it cannot close the attribute it lands in.Tests:
scripts/preview.imageReload.test.tsrunsprocessMarkdownHtmlon stamped markup: the image block changes and the text block does not, the URL gets?v=1then?v=2, the stamp attribute does not reach the preview, remote URLs are untouched, and an<imginside an attribute value leaves the attribute whole (red with a quoted stamp).documents.conflicts.spec.tschecks that both reload commands start a new generation. Reverting the fix removes the functions these call, so they fail to load rather than going red on an assertion.npm run check, the node suite (952) and vitest (744) pass. Tried in a macOS release build: overwrote a PNG red to green to blue, and each Reload showed the new colour. Not tried on Windows.